<?php
/**
 * 作用：命令行控制器基础类
 * @author liwei
 */
namespace Minicli;

class CommandController
{
    protected $app;

    protected $input;

    public function boot(App $app, CommandCall $input)
    {
        $this->app = $app;
        $this->input = $input;
    }

    public function teardown()
    {
        // 
    }

    // 获得所有输入参数
    protected function getArgs()
    {
        return $this->input->args;
    }

    protected function getParams()
    {
        return $this->input->params;
    }

    protected function hasParam($param)
    {
        return $this->input->hasParam($param);
    }

    protected function getParam($param)
    {
        return $this->input->getParam($param);
    }

    protected function getApp()
    {
        return $this->app;
    }

    protected function getPrinter()
    {
        return $this->getApp()->getPrinter();
    }

    public function __call($funcName, $args)
    {
        $this->getPrinter()->display('[ '. $funcName . ' ] method not found');
    }

    public function __get($name)
    {
        $this->getPrinter()->display($funcName . ' parameter not exists');
    }

    public function help()
    {
        $this->getPrinter()->display("This is help action, please read readme.md.");
    }
}
